﻿using System.Threading.Tasks;
using Coravel.Invocable;
using Microsoft.Extensions.Logging;
using Z.EntityFramework.Plus;

namespace CRM.Jobs
{
    /// <summary>
    /// 重置每日邮件发送数量
    /// <para>防止数据表过大</para>
    /// </summary>
    public class ResetEmailDailySendNum : IInvocable
    {
        private readonly MyDbContext _dbContext;
        private readonly ILogger<ResetEmailDailySendNum> _logger;

        public ResetEmailDailySendNum(MyDbContext dbContext, ILogger<ResetEmailDailySendNum> logger)
        {
            _dbContext = dbContext;
            _logger = logger;
        }

        public async Task Invoke()
        {
            var result = await _dbContext.EmailConfig.UpdateAsync(e =>
                new()
                {
                    LastDaySendNum = 0
                });

            _logger.LogInformation("重置每日邮件发送数量成功");
        }
    }
}